//
//  TitleView.m
//  宜居HD
//
//  Created by 张金国 on 16/4/25.
//  Copyright © 2016年 张金国. All rights reserved.
//

#import "TitleView.h"
#import "Masonry.h"

@interface TitleView ()
/**
 *  竖线
 */
@property (nonatomic, strong)UILabel *lineLabel;
/**
 *  标题的label
 */
@property (nonatomic, strong)UILabel *titleLabel;

@end

@implementation TitleView


#pragma mark - init Override

- (TitleView *)initWithLineColor:(UIColor *)lineColor title:(NSString *)title titleFont:(UIFont *)titleFont {
    if (self = [super init]) {
        UILabel *lineLabel = [[UILabel alloc]init];
        lineLabel.backgroundColor = lineColor;
        [self addSubview:lineLabel];
        self.lineLabel = lineLabel;
        UILabel *titleLabel = [[UILabel alloc]init];
        [self addSubview:titleLabel];
        self.titleLabel = titleLabel;
        self.lineLabel = lineLabel;
        self.titleLabel.text = title;
        self.titleLabel.font = titleFont;
        [self setupConstraints];
    }
    return self;
}

#pragma mark - Private
- (void)setupConstraints {
    [self.lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(5);
        make.left.equalTo(self);
        make.width.equalTo(@2);
        make.bottom.equalTo(self.mas_bottom).offset(-5);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self.lineLabel.mas_right).offset(10);
        make.height.equalTo(self.mas_height);
        make.right.equalTo(self.mas_right);
    }];
}

#pragma mark - Getter
- (UILabel *)lineLabel {
    if (!_lineLabel) {
        _lineLabel = [[UILabel alloc]init];
    }
    return _lineLabel;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
    }
    return _titleLabel;
}
@end
